package com.github.apollo;


import com.github.apollo.router.PersonRouter;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.ipc.netty.http.server.HttpServer;

public class ApolloServer {

    private static final String HOST = "localhost";
    private static final int PORT = 8080;


    private PersonRouter personRouter = new PersonRouter();

    public static void main(String[] args) throws Exception {


        ApolloServer server = new ApolloServer();
        server.startReactorServer();

    }


    private void startReactorServer() throws InterruptedException {
        RouterFunction<ServerResponse> router = personRouter.rout();
        HttpHandler httpHandler = RouterFunctions.toHttpHandler(router);


        ReactorHttpHandlerAdapter handlerAdapter = new ReactorHttpHandlerAdapter(httpHandler);
        HttpServer httpServer = HttpServer.create(HOST, PORT);
        httpServer.newHandler(handlerAdapter).block();

    }
}
